package com.oauth.global.client.ui.status.handlers;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Button;
import com.oauth.global.client.ui.status.StatusTextArea;

public class StatusValueChangeHandler implements ValueChangeHandler<String> {
	private StatusTextArea statusTextArea;
	private Button shareButton;

	public StatusValueChangeHandler(StatusTextArea pStatusTextArea, Button pShareButton) {
		statusTextArea = pStatusTextArea;
		shareButton = pShareButton;
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> pEvent) {
		String statusText = pEvent.getValue();
		if (isEmpty(statusText) || statusText.equalsIgnoreCase(statusTextArea.getDefaultText())) {
			shareButton.setEnabled(false);
		} else {
			shareButton.setEnabled(true);
		}
	}

	private boolean isEmpty(String pStatusText) {
		return pStatusText == null || pStatusText.trim().length() == 0;
	}

}
